target = 4
nums = [1,4,4]
n = len(nums)
i = j = 0
ans = nums[0]
tmp = ret = float('inf')
while j < n:
    if ans < target:
        j += 1
        if j == n:
            break
        ans += nums[j]
    else:
        tmp = j - i + 1
        ans -= nums[i]
        i += 1
        ret = min(tmp, ret)
if ret == float('inf'):
    print(0)
# # 排序后从左开始遍历，ans = 暂时的大小
# while left>0:
#     if nums[left] + ans < target:
#         ans += nums[left]
#         left -= 1
#         ret += 1
#     else:
#         ret += 1
#         break
#     # 特殊情况，最后一个数加上后是否满足target
#     if left == 0 and ans + nums[0] < target:
#         print(0)
#     elif left == 0 and ans + nums[0] >= target:
#         ret += 1
print(ret)